package com.itheima.mapper;

import com.itheima.pojo.Order;
import com.itheima.pojo.User;
import com.itheima.pojo.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

// 注解的多表查询
public interface UserMapperMoreTable {
    // 通过id查询用户扩展信息
    @Select("SELECT*FROM user_info WHERE id=#{uid};")
    UserInfo findUserInfoById(int uid);
    @Select("SELECT*FROM `order` WHERE oid=#{oId};")
    Order findOrder(int oId);

    // 通过id查询用户基本信息
    // @Results: 相当于 resultMap手动处理查询结果
    // @Result: 相当于 result标签,配置一个字段对应一个成员变量, id=true相当于id标签, id=false相当于result标签
    @Select("SELECT*FROM USER WHERE id=#{uid};")
    @Results({
            @Result(column = "id",property = "id",id=true),
            @Result(column = "username",property = "username"),
            @Result(column = "birthday",property = "birthday"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "address",property = "address"),
            @Result(property = "userInfo",column = "id",one = @One(select="findUserInfoById")),
            @Result(property = "orders",column = "id",many = @Many(select = "findOrder"))
    })
    User findUserById(int uid);
}
